package com.ruoyi.tongyan.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tongyan.domain.TDeclaration;
import com.ruoyi.tongyan.service.ITDeclarationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科研项目申报Controller
 *
 * @author ruoyi
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/tongyan/declaration")
public class TDeclarationController extends BaseController
{
    @Autowired
    private ITDeclarationService tDeclarationService;

    /**
     * 查询科研项目申报列表
     */
    @PreAuthorize("@ss.hasPermi('tongyan:declaration:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDeclaration tDeclaration)
    {
        startPage();
        List<TDeclaration> list = tDeclarationService.selectTDeclarationList(tDeclaration);
        return getDataTable(list);
    }

    /**
     * 导出科研项目申报列表
     */
    @PreAuthorize("@ss.hasPermi('tongyan:declaration:export')")
    @Log(title = "科研项目申报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TDeclaration tDeclaration)
    {
        List<TDeclaration> list = tDeclarationService.selectTDeclarationList(tDeclaration);
        ExcelUtil<TDeclaration> util = new ExcelUtil<TDeclaration>(TDeclaration.class);
        util.exportExcel(response, list, "科研项目申报数据");
    }

    /**
     * 获取科研项目申报详细信息
     */
    @PreAuthorize("@ss.hasPermi('tongyan:declaration:query')")
    @GetMapping(value = "/{declarationId}")
    public AjaxResult getInfo(@PathVariable("declarationId") Long declarationId)
    {
        return success(tDeclarationService.selectTDeclarationByDeclarationId(declarationId));
    }

    /**
     * 新增科研项目申报
     */
    @PreAuthorize("@ss.hasPermi('tongyan:declaration:add')")
    @Log(title = "科研项目申报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDeclaration tDeclaration)
    {

        return toAjax(tDeclarationService.insertTDeclaration(tDeclaration));
    }

    /**
     * 修改科研项目申报
     */
    @PreAuthorize("@ss.hasPermi('tongyan:declaration:edit')")
    @Log(title = "科研项目申报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDeclaration tDeclaration)
    {
        return toAjax(tDeclarationService.updateTDeclaration(tDeclaration));
    }

    /**
     * 删除科研项目申报
     */
    @PreAuthorize("@ss.hasPermi('tongyan:declaration:remove')")
    @Log(title = "科研项目申报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{declarationIds}")
    public AjaxResult remove(@PathVariable Long[] declarationIds)
    {
        return toAjax(tDeclarationService.deleteTDeclarationByDeclarationIds(declarationIds));
    }
}
